package cn.smilefox.dao.impl;

import cn.smilefox.dao.UseDao;
import cn.smilefox.domain.Use;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class UseDaoImpl implements UseDao {
    private JdbcTemplate jdbcTemplate;
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    //登录
    @Override
    public Use login(Use use) {
        Use use2 = jdbcTemplate.queryForObject("select * from use_table where use_name=?", new RowMapper<Use>() {
            @Override
            public Use mapRow(ResultSet resultSet, int i) throws SQLException {
                String use_password = resultSet.getString("use_password");
                String use_name = resultSet.getString("use_name");
                System.out.println("//////");
                System.out.println(use_password);
                Use use1 = new Use();
                use1.setUse_password(use_password);
                use1.setUse_name(use_name);
                return use1;
            }
        }, use.getUse_name());
        return use2;
    }

    //注册
    @Override
    public void register(Use use) {
//        jdbcTemplate.update("insert into use_table values (?,?,?,?,?)",null,use.getUse_name(),use.getUse_password(),use.getPhone_num(),use.getUse_type());
    }

    //检查用户名一致性
    @Override
    public List<Use> namecheck(String use_name) {
        List<Use> query = jdbcTemplate.query("select * from use_table where use_name = ?", new BeanPropertyRowMapper<Use>(Use.class), use_name);
        return query;
    }


}